package com.jian.socks5.udp.handler;

import com.jian.socks5.common.Constants;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.util.concurrent.EventExecutorGroup;

/***
 *
 * @author Jian
 * @date 2021.06.22
 */
public class UDPChannelInitializer extends ChannelInitializer<Channel> {

    private EventExecutorGroup eventExecutors;

    private static UDPChannelInitializer udpChannelInitializer;

    public static UDPChannelInitializer getUDPChannelInitializer(EventExecutorGroup eventExecutors){
        if (udpChannelInitializer == null) {
            udpChannelInitializer = new UDPChannelInitializer(eventExecutors);
        }
        return udpChannelInitializer;
    }

    public UDPChannelInitializer(EventExecutorGroup eventExecutors) {
        this.eventExecutors = eventExecutors;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(Constants.udpDatagramHandler);
    }
}
